<template>
  <div class="wrapper">
    <minbar title="订单详情" :isPadding="true"></minbar>
    <scroller class="x-scroller">
      <image class="x-image" :src="imageurl"></image>

      <!-- 收货地址 -->
      <div class="x-content-div">
        <text class="x-content-icon iconfont">&#xe650;</text>
        <div class="x-content-info">
          <text class="x-content-name">收货人：{{address.name}} {{address.mobile}}</text>
          <text class="x-content-address">收货地址：{{address.detail}}</text>
        </div>
      </div>
      <!-- 商品详情 -->
      <orderpage :orderData="orderData" :img="orderimg"></orderpage>
      <!-- 联系卖家 -->
      <div class="x-content-div">
        <text class="x-content-icon2 iconfont">&#xe7bb;</text>
        <div class="x-content-info">
          <text class="x-content-name">联系卖家</text>
        </div>
      </div>
      <!-- 订单详细 -->
      <div class="x-content-detail">
        <text class="x-content-text">订单号：{{orderData.sn}}</text>
        <text class="x-content-text">创建时间：{{getCreateTime(orderData.create_time)}}</text>
        <text class="x-content-text">付款时间：{{orderData.update_time}}</text>
      </div>
    </scroller>
    <!-- 底部按钮 -->
    <div class="x-bottom">
      <text class="x-button-two">查看物流</text>
      <text class="x-button-two">延长收货</text>
      <text class="x-button-one">确认收货</text>
    </div>
  </div>
</template>

<script>
import asCore from "../../../common/js/core";
const navigator = weex.requireModule('navigator');
export default { 
  components: {
    "button": require("../../../common/component/button.vue"),
    "minbar" : require("../../../common/component/minbar.vue"),
    "orderpage" : require("./comp/detailPage.vue"),
  },
  data() {
    return {
      sno:"",
      imageurl:asCore.localpath + 'img/order/detail.png',
      orderimg:asCore.localpath + 'img/order/order.png',
      orderData:{coin:0},
      address:{
        name:"",
        mobile:"",
        detail:""
      }
    };
  },
  created() {
    var _this = this;
    var globalEvent = weex.requireModule('globalEvent') ;
    globalEvent.addEventListener("onPageInit", function (e) {
      var param = navigator.param();
      _this.sno = param['sno'];
      _this.getData();
    });
  },
  methods: {
    /**获取主数据 */
    getData(){
      asCore.post("/member/order/get",{order_sn:this.sno},(data,msg,flag)=>{
        //asCore.alert(JSON.stringify(data));
        if(flag==true){
          this.orderData = data;
          this.address = data['address'];
        }
      });
    },
    getCreateTime(time){
      return this.formatDate(new Date(time),"yyyy-MM-dd hh:mm:ss");
    },
    formatDate(date, fmt){
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
        'M+': date.getMonth() + 1,
        'd+': date.getDate(),
        'h+': date.getHours(),
        'm+': date.getMinutes(),
        's+': date.getSeconds()
      };
      for (let k in o) {
        if (new RegExp(`(${k})`).test(fmt)) {
            let str = o[k] + '';
            fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? str : this.padLeftZero(str));
        }
      }
      return fmt;
    },
    padLeftZero(str) {
      return ('00' + str).substr(str.length);
    }
  }
};
</script>
<style scoped>
.wrapper {
  background-color: #dedfe1;
  position: relative;
}
.iconfont {
    font-family:iconfont;
}
.x-image {
  width: 750px;
  height: 190px;
}
.x-content-div {
  background-color: #fff;
  margin-top:20px;
  margin-bottom: 20px;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  padding: 20px;
  padding-left: 20px;
  padding-right: 20px;
}
.x-content-div:active{
  background-color: #eee;
}
.x-content-icon {
  width: 80px;
  font-size:50px;
  color:#2e2e4d;
}
.x-content-info {
  flex: 1;
}
.x-content-name {
  font-size: 32px;
  color: #1f1e23;
}
.x-content-address {
  padding-top:10px;
  font-size:28px;
  color: #1f1e23;
}
.x-content-icon2 {
  width: 65px;
  font-size:50px;
  color:#887145;
}
.x-content-detail {
  background-color: #fff;
  padding: 20px;
}
.x-content-text {
  color:#1f1e24;
  font-size:28px;
  padding-bottom:5px;
}
.x-bottom {
  position: absolute;
  bottom: 0;
  width: 750px;
  height: 100px;
  background-color: #fff;
  box-shadow: 2px 2px 5px #999;
  flex-direction: row;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
}
.x-scroller {
  position: absolute;
  top: 130px;
  left: 0;
  right: 0;
  bottom: 100;
}
.x-button-one {
    color: #ae0a2c;
    height:60px;
    line-height: 60px;
    text-align: center;
    font-size:28px;
    padding-left:28px;
    padding-right: 28px;
    border-color: #ae0a2c;
    border-width: 1px;
    border-radius: 50px;
    margin-left:20px;
}
.x-button-two {
    color: #232325;
    height:60px;
    line-height: 60px;
    text-align: center;
    font-size:28px;
    padding-left:28px;
    padding-right: 28px;
    border-color: #b7b6bc;
    border-width: 1px;
    border-radius: 50px;
    margin-left:20px;
}
.x-button-one:active {
    background-color: #ae0a2c;
    color: #fff;
}
.x-button-two:active {
    background-color: #ae0a2c;
    color: #fff;
}
</style>
